package map.android.baidu.carpool.reservation;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import android.content.Context;
import map.android.baidu.carpool.utils.TimeUtil;
import map.android.baidu.carpool.widget.wheel.AbstractWheelTextAdapter;

/**
 * Adapter class for old wheel adapter (deprecated WheelAdapter class).
 * 
 */
public class DaysWheelAdapter extends AbstractWheelTextAdapter {

	private List<Calendar> mList;

	private boolean mTodayStatus;
	
	public void setData(List<Calendar> list) {
		mList = list;
	}

	/**
	 * Constructor
	 * 
	 * @param context
	 *            the current context
	 */
	public DaysWheelAdapter(Context context) {
		super(context);
	}

	public Calendar getItem(int index) {
		return mList == null ? null : mList.get(index);
	}

	@Override
	public CharSequence getItemText(int index) {
		Calendar calendar = getItem(index);
		if (calendar == null) {
			return "现在用车";
		}if (index == 0 && ismTodayStatus()) {
				Date date = calendar.getTime();
				SimpleDateFormat f = new SimpleDateFormat("E");
				return "今天 "+f.format(date);
		}else if (TimeUtil.isTomorrow(calendar)){
			Date date = calendar.getTime();
			SimpleDateFormat f = new SimpleDateFormat("E");
			return "明天 "+f.format(date);

		}else if (TimeUtil.isAfter(calendar)){
			Date date = calendar.getTime();
			SimpleDateFormat f = new SimpleDateFormat("E");
			return "后天 "+f.format(date);

		}
		else {
			Date date = calendar.getTime();
			SimpleDateFormat f = new SimpleDateFormat("MM月dd日 E");
			return f.format(date);
		}
	}

	@Override
	public int getItemsCount() {
		if (mList == null) {
			return 0;
		}
		return mList.size();
	}
	
	public boolean ismTodayStatus() {
		return mTodayStatus;
	}

	public void setmTodayStatus(boolean mTodayStatus) {
		this.mTodayStatus = mTodayStatus;
	}

}
